<?php

class Nld_Models_Navigate_Row extends Core_Db_Table_Row_Abstract
{
	public function _doInsert()
	{
		$this->created    = time();
		$this->created_by = @Nld_Auth_Users::getInstance()->getIdentity()->username;
		$this->updated    = time();
		$this->updated_by = @Nld_Auth_Users::getInstance()->getIdentity()->username;
		
		return parent::_doInsert();
	}
	public function _doUpdate()
	{
		$this->updated    = time();
		$this->updated_by = @Nld_Auth_Users::getInstance()->getIdentity()->username;

		return parent::_doUpdate();
	}
  public function getParent()
  {
    return $this->getTable()->fetchRow('`id` = '.intval($this->parent));
  }
	public function getParents()
	{
		$entries  = array();
		$entry 		= $this;
    while(($entry = $entry->getParent()) && !is_null($entry))
    {
			$entries[] = $entry;
    }
		return array_reverse($entries);
	}
	public function getLevelTitle()
  {
		$level = count($this->getParents());
		if($level == 0)
		{
			return $this->title;
		}
    return str_repeat('----|---- ', $level).' '.$this->title;
  }
}